Ext.namespace("Info.Confirem");

Info.Confirem.win = function() {
	this.loadMask = null;
	this.BpsUrl;
	this.infoId;
	this.processinstid;
	this.connBpsUrl = new Ext.data.Connection({
		url:'../info/getBpsUrl.form?timesnap=' + Date.parse(new Date()),
		method:'post'
	});
	this.btnShowImage = new Ext.Button({
		 text:'查看流程',
		 handler:this.ShowImage,
         scope: this
	});
	this.createUser = new Ext.form.TextField({
        fieldLabel: '上报人',
        width: 200,
        disabled:true
    });
	this.txtHeader = new Ext.form.TextField({
        fieldLabel: '信息名称',
        width: 200,
        disabled:true
    });
	this.infoType = new Ext.form.ComboBox({
		width: 100,
		fieldLabel: '信息类型',
        store: new Ext.data.ArrayStore({
        	fields: ['value', 'name'],
        	data: OMS.INFO_TYPE2
        }),
        value: 0,
        valueField: 'value',
        displayField: 'name',
        editable: false,
        disabled:true,
        mode: 'local',
        triggerAction: 'all',
        selectOnFocus: true
	});
	this.instancyLevel = new Ext.form.ComboBox({
		width: 100,
		fieldLabel: '紧急级别',
        store: new Ext.data.ArrayStore({
        	fields: ['value', 'name'],
        	data: OMS.INFO_INSTANCY_LEVEL2
        }),
        value: 0,
        valueField: 'value',
        displayField: 'name',
        editable: false,
        disabled:true,
        mode: 'local',
        triggerAction: 'all',
        selectOnFocus: true
	});
	this.infoDept = new Ext.form.TextField({
        fieldLabel: '所属部门',
        width: 200,
        disabled:true
    });
	this.txtContent = new Ext.form.HtmlEditor({
		fieldLabel: '信息内容',
		width:555,
		height:100,
		//readOnly:true,
		autoScroll:true
	});
	this.submitTime = new Ext.ux.form.DateTime({
		fieldLabel: '上报时间',
		timeFormat:'H:i',
        timeConfig: {
            altFormats:'H:i',
            allowBlank: true,
            disabled:true   
        },
        dateFormat:'Y-m-d',
        dateConfig: {
            altFormats:'Y-m-d',
            allowBlank: false,   
            disabled:true 
       }
	});
	this.lastFinishTime = new Ext.ux.form.DateTime({
		fieldLabel: '完成时限',
		timeFormat:'H:i',
        timeConfig: {
            altFormats:'H:i',
            allowBlank: true,
            disabled:true   
        },
        dateFormat:'Y-m-d',
        dateConfig: {
            altFormats:'Y-m-d',
            allowBlank: false,   
            disabled:true 
       }
	});
	this.txtAnswerInfo = new Ext.form.TextArea({
		fieldLabel: '回复内容',
		width:555,
		maxLength:500,
		height:50,
		readOnly:true,
		autoScroll:true
	});
	this.backReason = new Ext.form.TextArea({
		fieldLabel: '退回原因',
		width:555,
		height:50,
		maxLength:500,
		autoScroll:true
	});
	this.importFile = new Ext.form.TextField({
        fieldLabel: '附件上传',
        width: 400,
        inputType:'file'
    });
	this.btnCommit = new Ext.Button({
		 text:'退 回',
		 handler:this.Commit,
         scope: this
	});
	this.btnComplete = new Ext.Button({
		 text:'确认解决',
		 handler:this.Complete,
         scope: this
	}); 
	this.tabPanel  = new Ext.TabPanel({
		height:450
	});
	this.formFieldSet = new Ext.form.FieldSet({
        title: '基本信息',
        autoHeight: true,
        autoWidth:true,
        items:[{
               layout:'column',
               autoScroll:true,
               items:[
                      {columnWidth:.5,
                      layout:'form',
                      items:[
                             this.createUser,this.txtHeader, this.infoType
				      ]},
					   {columnWidth:.5,
	                       layout:'form',
					       items:[
					              this.instancyLevel, this.submitTime,this.lastFinishTime
					  ]},
					  {columnWidth:1,
						   	layout:'form',
						   	 items:[this.txtContent
				     ]},
					  {columnWidth:1,
						   	layout:'form',
						   	 items:[this.txtAnswerInfo
				     ]},
					  {columnWidth:1,
						   	layout:'form',
						   	 items:[this.backReason
				     ]}
               ]
        }]
    });
	this.form = new Ext.form.FormPanel({
        frame:true,
        autoWidth:true,
       	layout:'form',
        items: [this.formFieldSet]
    });
	this.commitCon = new Ext.data.Connection({
		url:'../info/back.form?timesnap=' + Date.parse(new Date()),
		method:'post'
	});
	this.completeCon = new Ext.data.Connection({
		url:'../info/finishInfo.form?timesnap=' + Date.parse(new Date()),
		method:'post'
	});
	
	Info.Confirem.win.superclass.constructor.call(this, {
		title: '信息上报',
        autoHeight: true,
        width: 750,
        resizable: true,
        autoScroll: true,
        closeAction: 'hide',
        layout:'form',
        items: [this.form],
        buttonAlign:'center',
        buttons: [this.btnShowImage,this.btnCommit,this.btnComplete,new Ext.Button({text:'关闭',scope:this,handler:function(){this.hide();}})]
        
	});
};
Ext.extend(Info.Confirem.win, Ext.Window, {
	initDetail:function(data){
		this.form.getForm().reset();
		this.createUser.setValue(data.createUser);
		this.infoId = data.infoId;
		this.processinstid = data.processinstid;
		this.txtHeader.setValue(data.infoHeader);
		this.txtContent.setValue(data.infoContent);
		this.txtAnswerInfo.setValue(data.answerInfo);
		this.submitTime.setValue(Date.parseDate(data.reportTime,'Y-m-d H:i'));
		this.lastFinishTime.setValue(Date.parseDate(data.lastFinishTime,'Y-m-d H:i'));
		this.infoType.setValue(data.infoType);
		this.instancyLevel.setValue(data.instancyLevel);
		this.infoDept.setValue(data.department);
		this.backReason.setValue(data.backCause);
	},
	Commit: function() {
		if(!this.form.getForm().isValid()){
			Utils.info("有必填项没有填写，请检查！","系统提示");
			return;
		}
		if(this.backReason.getValue() ==""){
			Utils.info("请输入退回原因！");
			return;
		}
		if(!confirm("确定要退回吗？")){
			return;
		}
		if (!this.loadMask) {
			 this.loadMask = new Ext.LoadMask(this.form.getEl(), {msg: '转交中，请稍候...'});
		}
		Utils.request(this.commitCon,{
			params:{
				infoId:this.infoId,
				processinstid:this.processinstid,
				backCause:this.backReason.getValue()
			},
			scope:this,
			success:function(){
				Utils.info("操作成功","系统提示");
				this.scope.hide();
				Info.Prepare.panel.instance.store.reload();
			}
		});
		
	},
	Complete: function() {
		if(!this.form.getForm().isValid()){
			Utils.info("有必填项没有填写，请检查！","系统提示");
			return;
		}
		if(!confirm("确定要结束吗？")){
			return;
		}
		if (!this.loadMask) {
			 this.loadMask = new Ext.LoadMask(this.form.getEl(), {msg: '处理中，请稍候...'});
		}
		Utils.request(this.completeCon,{
			params:{
				infoId:this.infoId,
				processinstid:this.processinstid,
				backCause:this.backReason.getValue()
			},
			scope:this,
			success:function(){
				Utils.info("操作成功","系统提示");
				this.scope.hide();
				Info.Prepare.panel.instance.store.reload();
			}
		});
	 
	},
	ShowImage:function(){
		if(this.BpsUrl){
			var url=this.BpsUrl+'/bpsroot/bps_ext.pr.login.do?processInstID='+this.processinstid+'&processDefID=&processDefName=&showUrl=&url=&target=&zoomQuotiety=1.0&xpath=&iframeWidth=100%&iframeHeight=200';
   	 		window.open(url, "newWindow", "height=400, width=600, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no");
		}
		else{
			Utils.request(this.connBpsUrl,{
				scope:this,
				success:function(resp, action){
					this.scope.BpsUrl=resp.bpsUrl;
					var url=this.scope.BpsUrl+'/bpsroot/bps_ext.pr.login.do?processInstID='+this.scope.processinstid+'&processDefID=&processDefName=&showUrl=&url=&target=&zoomQuotiety=1.0&xpath=&iframeWidth=100%&iframeHeight=200';
   	 				window.open(url, "newWindow", "height=400, width=600, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no");
				}
			});
		}
	}
});

